import { PageModalService } from 'src/app/shared/service/page-modal-service';
import { Component, Input, OnInit } from '@angular/core';
import { HttpService } from 'src/app/shared/service/http.service';
import { AppGlobalService } from 'src/app/shared/service/app-global.service';

@Component({
  selector: 'app-service-status',
  templateUrl: './service-status.component.html',
  styleUrls: ['./service-status.component.scss'],
})
export class ServiceStatusComponent implements OnInit {
  @Input() tagData: any;
  constructor(
    private pageModalService: PageModalService,
    public appGlobalService: AppGlobalService,
    public httpService: HttpService,
  ) { }

  ngOnInit() { }
  openPage(item) {
    if (item.submit) {
      const params = {
        content: item.submit.content,
        id: item.submit.id,
        sessionId: localStorage.getItem("sessionId")
      };
      this.httpService.post("application/submit", params, res => {
        this.appGlobalService.showToast(res.message, 1500, "middle");
        if (res.success) {
          if (res.target) {
            const pageLink = {
              type: 'pageModal',
              target: res.target,
              params: res.params,
              sessionId: localStorage.getItem("sessionId")
            };
            if (res.skip === 0 || res.skip === 1) { // page
              pageLink.type = 'page';
            } else if (res.skip === 4) { // pageModal
              pageLink.type = 'pageModal';
            }
            this.pageModalService.openPage(pageLink);
          }
        }
      });
    } else if (item.link) {
      this.pageModalService.openPage(item.link);
    }

  }
}
